<?php

namespace app\api\model\user;

use app\api\model\UserModel;
use app\logic\model\user\UserFollowLogicModel;

class UserFollowApiModel extends UserFollowLogicModel
{

    public static function checkFollow($id, $user_id): bool
    {
        if(empty($id) || empty($user_id)){
            return false;
        }
        return (bool)self::where('writer_id',$id)
            ->where('user_id',$user_id)->find();
    }

    function follow_op($user_id, $writer_id){
        $info = $this->where('user_id',$user_id)
            ->where('writer_id',$writer_id)
            ->find();
        if(empty($info)){
            $this->save([
                'user_id'=>$user_id,
                'writer_id'=>$writer_id,
            ]);
            //fans_num +1;
            return 1;
        }else{
            $info->delete();
            return -1;
        }
    }
}